package jade.oo.core.behaviours;

import jade.core.AID;
import jade.core.Agent;
import jade.lang.acl.ACLMessage;

import java.io.IOException;
import java.io.Serializable;

public class OutboxImpl implements Outbox {

	private final Agent agent;

	public OutboxImpl(Agent agent) {
		this.agent = agent;
	}

	@Override
	public void send(Serializable message, AID recipient) {
		ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
		try {
			msg.setContentObject(message);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		msg.setSender(agent.getAID());
		msg.addReceiver(recipient);
		agent.send(msg);
	}

}
